import pygame
from random import randint
class Obstacle(pygame.sprite.Sprite):
    #需要给出类型
    def __init__(self,type):
        super().__init__()
        if type == 'bone':
            bone_1 = pygame.transform.scale(pygame.image.load('game_custom/monster/bone1.png').convert_alpha(),(84,40))
            bone_2 = pygame.transform.scale(pygame.image.load('game_custom/monster/bone2.png').convert_alpha(),(84,40))
            self.frames = [bone_1,bone_2]
            y_pos = 812
        elif type == 'fly':
            fly_1 = pygame.transform.scale(pygame.image.load('game_custom/monster/fly1.png').convert_alpha(),(82,36))
            fly_2 = pygame.transform.scale(pygame.image.load('game_custom/monster/fly2.png').convert_alpha(),(82,36))
            self.frames = [fly_1,fly_2]
            y_pos = 612
        elif type == 'ghost':
            ghost_1 = pygame.transform.scale(pygame.image.load('game_custom/monster/ghost1.png').convert_alpha(),(102,56))
            ghost_2 = pygame.transform.scale(pygame.image.load('game_custom/monster/ghost2.png').convert_alpha(),(102,56))
            ghost_3 = pygame.transform.scale(pygame.image.load('game_custom/monster/ghost3.png').convert_alpha(),(102,56))
            self.frames = [ghost_1,ghost_2,ghost_3]
            y_pos = 612
        elif type == 'animal':
            animal_1 = pygame.transform.scale(pygame.image.load('game_custom/monster/animal1.png').convert_alpha(),(84,40))
            animal_2 = pygame.transform.scale(pygame.image.load('game_custom/monster/animal2.png').convert_alpha(),(84,40))
            animal_3 = pygame.transform.scale(pygame.image.load('game_custom/monster/animal3.png').convert_alpha(),(84,40))
            self.frames = [animal_1,animal_2,animal_3]
            y_pos = 812
        elif type == 'bigmonster':
            bigmonster_1 = pygame.transform.scale(pygame.image.load('game_custom/monster/bigmonster1.png').convert_alpha(),(84,40))
            bigmonster_2 = pygame.transform.scale(pygame.image.load('game_custom/monster/bigmonster2.png').convert_alpha(),(84,40))
            bigmonster_3 = pygame.transform.scale(pygame.image.load('game_custom/monster/bigmonster3.png').convert_alpha(),(84,40))
            bigmonster_4 = pygame.transform.scale(pygame.image.load('game_custom/monster/bigmonster4.png').convert_alpha(),(84,40))
            bigmonster_5 = pygame.transform.scale(pygame.image.load('game_custom/monster/bigmonster5.png').convert_alpha(),(84,40))
            bigmonster_6 = pygame.transform.scale(pygame.image.load('game_custom/monster/bigmonster6.png').convert_alpha(),(84,40))
            self.frames = [bigmonster_1,bigmonster_2,bigmonster_3,bigmonster_4,bigmonster_5,bigmonster_6]
            y_pos = 812
        elif type == 'lmonster':
            lmonster_1 = pygame.transform.scale(pygame.image.load('game_custom/monster/lmonster1.png').convert_alpha(),(84,40))
            lmonster_2 = pygame.transform.scale(pygame.image.load('game_custom/monster/lmonster2.png').convert_alpha(),(84,40))
            lmonster_3 = pygame.transform.scale(pygame.image.load('game_custom/monster/lmonster3.png').convert_alpha(),(84,40))
            lmonster_4 = pygame.transform.scale(pygame.image.load('game_custom/monster/lmonster4.png').convert_alpha(),(84,40))
            lmonster_5 = pygame.transform.scale(pygame.image.load('game_custom/monster/lmonster5.png').convert_alpha(),(84,40))
            lmonster_6 = pygame.transform.scale(pygame.image.load('game_custom/monster/lmonster6.png').convert_alpha(),(84,40))
            self.frames = [lmonster_1,lmonster_2,lmonster_3,lmonster_4,lmonster_5,lmonster_6]
            y_pos = 812
        #动画索引
        self.animation_index = 0

        self.image = self.frames[self.animation_index]
        self.rect = self.image.get_rect(midbottom=(randint(1100,1400),y_pos))

    def animation_state(self):
        self.animation_index += 0.1
        if self.animation_index >= len(self.frames):
            self.animation_index = 0
        self.image = self.frames[int(self.animation_index)]

    def update(self):
        self.animation_state()

        self.rect.x -= 6
        self.destroy()

    def destroy(self):
        if self.rect.x <= -100:
            self.kill()